import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LXW
 * Date: 2022-01-15
 * Time: 15:06
 */
public class MyStack {
    private int[] array;
    private int size;

    public MyStack() {
        this.array = new int[10];
    }
    public void push(int val) {
        if (this.size == array.length){  // 扩容
            array = Arrays.copyOf(array,2*array.length);
        }
        this.array[size] = val;
        this.size++;
    }
    public boolean isEmpty() {  // 判断栈是否为空
        return this.size == 0;
    }
    public int pop() {
        if (isEmpty()) {
            System.out.println("此栈为空");
        }
        this.size--;
        return array[size];
    }
    public int peek() {
        if (isEmpty()) {
            System.out.println("此栈为空");
        }
        return array[size-1];
    }
}
